package com.phynos.web.manager.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.phynos.dal.mapper.UserMapper;
import com.phynos.dal.model.User;
import com.phynos.web.manager.json.JsonResult;
import com.phynos.web.manager.json.ResultCodeEnum;

public class ManulTransactionService extends BaseService {

	@Autowired
	private UserMapper userMapper;
	
	@Autowired
	private DataSourceTransactionManager transactionManager;
	
	public User getUser(long id) {
		return userMapper.getUser(id);
	} 
	
	@Transactional
	public JsonResult addUser(){
		return JsonResult.code(ResultCodeEnum.UNSURPORT);
	}
	
	public JsonResult deleteUser(int id){
		DefaultTransactionDefinition transDefinition = new DefaultTransactionDefinition();
		//开启新事务
		transDefinition.setPropagationBehavior(DefaultTransactionDefinition.PROPAGATION_REQUIRES_NEW);
		TransactionStatus transStatus = transactionManager.getTransaction(transDefinition);
		try {
			//执行操作
			
			transactionManager.commit(transStatus);
		} catch (Exception e) {
			transactionManager.rollback(transStatus);
		}
		return JsonResult.code(ResultCodeEnum.UNSURPORT);
	}
	
}
